﻿<%@ Page Title="" Language="C#" MasterPageFile="~/UI/Main.Master" AutoEventWireup="true" CodeBehind="sanpham.aspx.cs" Inherits="QLBH.UI.sanpham" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <style type="text/css">
        .popover {
            width: 276px;
        }

        .popover-title {
            padding: 0px;
        }


        .popover-content {
            max-height: 276px;
            overflow: auto;
        }

        table th {
            font-size: 16px;
        }

        #table_quyen th {
            font-size: inherit;
        }

        table tr td {
            text-align: left;
        }

        .datepicker.dropdown-menu {
            z-index: 100000;
        }
    </style>


    <div class="row">
        <div class="col-md-4">
        </div>
        <div class="col-md-4 text-right" style="padding-bottom: 5px;">
            <span id="btn_refresh" class="btn btn-success"><span class="glyphicon glyphicon-refresh"></span></span>
            <span id="btn_add" data-toggle="popover" class="btn btn-primary">&nbsp<span class="glyphicon glyphicon-plus"></span></span>
            <span id="btn_edit" data-toggle="popover" class="btn btn-primary"><span class="glyphicon glyphicon-pencil"></span></span>
            <span id="btn_delete" data-toggle="popover" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></span>

        </div>
        <div class="col-md-4 text-right">
            <div class="form-group">
                <input type="search" class="form-control" id="txt_search" placeholder="Nhập vào tên sản phẩm" />
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 text-center" id="lazyScroll" style="overflow: auto; max-height: 310px;">

            <table id="table_san_pham" class="table table-bordered " style="min-width: 900px;">
                <thead>
                    <tr>
                        <th class="text-center" style="width: 30px;">
                            <input id="chk_check_all" type="checkbox" value="-1" />
                        </th>
                        <th class="text-center" style="width: 50px;">STT</th>
                        <th style="width: 100px;">Mã SP</th>
                        <th>Tên Sản phẩm</th>
                        <th>Giá bán</th>
                        <th>Đơn vị</th>
                        <th>Giảm giá</th>
                        <th style="width: 100px;">Tồn tối thiểu</th>
                        <th>Nhóm</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>

    <div id="popoverExampleTwoHiddenContent" style="display: none">

        <form role="form">
            <label id="lbl_lan_sua_cuoi" class="hidden"></label>

            <div class="form-group">
                <label for="cbo_nhom_sp">Nhóm sản phẩm</label>
                <select class="form-control" id="cbo_nhom_sp">
                </select>
            </div>

            <div class="form-group">
                <label for="txt_ma_sp">Mã Sản phẩm</label>
                <input type="text" class="form-control" name="txt_ma_sp" id="txt_ma_sp" placeholder="Mã sản phẩm" />
            </div>

            <div class="form-group">
                <label for="txt_ten_KH">Tên Sản phẩm</label>
                <input type="text" class="form-control" name="txt_ten_sp" id="txt_ten_sp" placeholder="Tên sản phẩm" />
            </div>
            <div class="form-group">
                <label for="txt_gia_ban">Giá bán</label>
                <input type="text" id="txt_gia_ban" onblur="this.value=formatCurrency(this.value)" class="form-control" placeholder="Giá bán" />
            </div>

            <div class="form-group">
                <label for="txt_dvtinh">Đơn vị</label>
                <input type="text" class="form-control" name="txt_dvtinh" id="txt_dvtinh" placeholder="Đơn vị" />
            </div>
            <div class="form-group">
                <label for="txt_ton_toi_thieu">Tồn tối thiểu</label>
                <input type="text" class="form-control" onblur="this.value=formatCurrency(this.value)" name="txt_ton_toi_thieu" id="txt_ton_toi_thieu" placeholder="Tồn tối thiểu" />
            </div>

            <div class="form-group">
                <label for="txt_ton_toi_da">Tồn tối đa</label>
                <input type="text" class="form-control" onblur="this.value=formatCurrency(this.value)" name="txt_ton_toi_da" id="txt_ton_toi_da" placeholder="Tồn tối đa" />
            </div>
            <div class="form-group">
                <label for="txt_giam_gia">Giảm giá</label>
                <input type="email" class="form-control" onblur="this.value=formatCurrency(this.value)" name="txt_giam_gia" id="txt_giam_gia" placeholder="Giảm giá" />
            </div>

            <div class="form-group">
                <label for="txt_mo_ta">Mô tả</label>
                <textarea rows="2" class="form-control" name="txt_mo_ta" id="txt_mo_ta" placeholder="Mô tả"></textarea>
            </div>

            <div class="form-group">
                <label for="txt_nha_sx">Nhà sx</label>
                <input type="text" class="form-control" name="txt_nha_sx" id="txt_nha_sx" placeholder="Nhà sản xuất" />
            </div>
            <div class="form-group">
                <label for="txt_xuat_xu">Xuất xứ</label>
                <input type="text" class="form-control" name="txt_xuat_xu" id="txt_xuat_xu" placeholder="Xuất xứ" />
            </div>

            <div class="form-group">
                <label for="txt_mau_sac">Màu sắc</label>
                <input type="text" class="form-control" name="txt_mau_sac" id="txt_mau_sac" placeholder="Màu sắc" />
            </div>
            <div class="form-group">
                <input type="checkbox" id="chk_hsd" />
                Có hạn sử dụng
            </div>
            <div class="form-group">
                <label for="txt_dai">Dài</label>
                <input type="text" class="form-control" name="txt_dai" id="txt_dai" placeholder="Dài" />
            </div>

            <div class="form-group">
                <label for="txt_rong">Rộng</label>
                <input type="text" class="form-control" name="txt_rong" id="txt_rong" placeholder="Rộng" />
            </div>

            <div class="form-group">
                <label for="txt_day">Dày</label>
                <input type="text" class="form-control" name="txt_day" id="txt_day" placeholder="Dày" />
            </div>

            <div class="form-group">
                <label for="txt_serial">Serial</label>
                <input type="text" class="form-control" name="txt_serial" id="txt_serial" placeholder="Serial" />
            </div>


            <button id="btn_save" type="submit" class="btn btn-primary pull-right">&nbsp&nbsp Lưu &nbsp&nbsp  </button>
        </form>

    </div>


    <!-- Popover 2 hidden title -->
    <div id="popoverExampleTwoHiddenTitle" style="display: none;">
        <h4 class="text-center">Cập nhật Sản phẩm</h4>
    </div>


    <script src="slidebars/scripts/bootstrap/js/jquery.min.js"></script>
    <script src="slidebars/scripts/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {

            $("#lazyScroll").scroll(function () {
                if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
                    var tables = document.getElementById("table_san_pham");
                    BlockUI();
                    var search_term = $("#txt_search").val();
                    TimSanPham(search_term, tables.rows.length - 1);
                }
            });

            function IsNumber(num) {
                if ($.isNumeric(num.toString().replace(/,/g, '')))
                    return true;
                return false;
            }

            function Kiemtrahople() {
                if ($('#txt_ten_sp').val().length <= 0) {
                    $('#txt_ten_sp').focus();
                    $('#txt_ten_sp').tooltip({ placement: 'top', title: 'Bạn cần nhập tên sản phẩm' });
                    return false;
                }

                if ($('#txt_gia_ban').val().length <= 0) {
                    $('#txt_gia_ban').focus();
                    $('#txt_gia_ban').tooltip({ placement: 'top', title: 'Bạn cần nhập giá bán' });
                    return false;
                }

                if (!IsNumber($('#txt_gia_ban').val())) {
                    $('#txt_gia_ban').focus();
                    $('#txt_gia_ban').tooltip({ placement: 'top', title: 'Giá bán không hợp lệ' });
                    return false;
                }

                if ($('#txt_giam_gia').val().length <= 0) {
                    $('#txt_giam_gia').focus();
                    $('#txt_giam_gia').tooltip({ placement: 'top', title: 'Bạn cần nhập giảm giá' });
                    return false;
                }

                if (!IsNumber($('#txt_giam_gia').val())) {
                    $('#txt_giam_gia').focus();
                    $('#txt_giam_gia').tooltip({ placement: 'top', title: 'Giảm giá không hợp lệ' });
                    return false;
                }

                if ($('#txt_dvtinh').val().length <= 0) {
                    $('#txt_dvtinh').focus();
                    $('#txt_dvtinh').tooltip({ placement: 'top', title: 'Bạn cần nhập đơn vị tính' });
                    return false;
                }

                if ($('#txt_dvtinh').val().length <= 0) {
                    $('#txt_dvtinh').focus();
                    $('#txt_dvtinh').tooltip({ placement: 'top', title: 'Bạn cần nhập đơn vị tính' });
                    return false;
                }

                if ($('#txt_ton_toi_thieu').val().length <= 0) {
                    $('#txt_ton_toi_thieu').focus();
                    $('#txt_ton_toi_thieu').tooltip({ placement: 'top', title: 'Bạn cần nhập đơn vị tính' });
                    return false;
                }

                if (!IsNumber($('#txt_ton_toi_thieu').val())) {
                    $('#txt_ton_toi_thieu').focus();
                    $('#txt_ton_toi_thieu').tooltip({ placement: 'top', title: 'Tồn tối thiểu không hợp lệ' });
                    return false;
                }

                return true;
            }

            function XoaText() {
                $('#txt_ma_sp').val('');
                $('#txt_ten_sp').val('');
                $('#txt_gia_ban').val('');
                $('#txt_dvtinh').val('');
                $('#txt_ton_toi_thieu').val('');
                $('#txt_ton_toi_da').val('');
                $('#txt_giam_gia').val('');
                $('#txt_mo_ta').val('');
                $('#txt_nha_sx').val('');
                $('#txt_xuat_xu').val('');

                $('#txt_mau_sac').val('');
                $('#txt_dai').val('');
                $('#txt_day').val('');
                $('#txt_rong').val('');
                $('#txt_serial').val('');
            }

            function BlockUI() {
                $.blockUI({
                    message: "<img src='images/ajax-loader.gif'/>", css: { left: '50%', cursor: 'wait', backgroundColor: 'none', border: 'none', width: '50px' },
                    overlayCSS: { backgroundColor: 'none', opacity: 0.0, cursor: 'wait' }
                });
            }

            function BlockUIPopover() {
                $('.popover').block({
                    message: "<img src='images/ajax-loader.gif'/>", css: { left: '50%', cursor: 'wait', backgroundColor: 'none', border: 'none', width: '50px' },
                    overlayCSS: { backgroundColor: 'none', opacity: 0.0, cursor: 'wait' }
                });
            }

            function TimSanPham(ten_san_pham, tong_so_dong) {

                var DTO = {
                    'ten_san_pham': ten_san_pham,
                    'tong_so_dong': tong_so_dong
                };
                $.ajax({
                    type: "POST",
                    url: "../BUSINESS/Services.asmx/TimSanPhamTheoTen",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {

                        $.each($.parseJSON(data.d), function (idx, obj) {
                            tong_so_dong += 1;
                            $("#table_san_pham tbody").append(
                            '<tr>' +
                            ' <td>' +
                            ' <input type="checkbox" value="' + tong_so_dong + '" />' +
                            ' </td>' +
                            ' <td>' + tong_so_dong + '</td>' +
                            ' <td>' + obj.MA_SAN_PHAM + '</td>' +
                            ' <td>' + obj.TEN_SAN_PHAM + '</td>' +
                            ' <td class="text-right">' + formatCurrency(obj.GIA_BAN) + '</td>' +
                            ' <td>' + obj.DON_VI_TINH + '</td>' +
                            ' <td class="text-right">' + formatCurrency(obj.GIAM_GIA) + '</td>' +
                            ' <td class="text-right">' + formatCurrency(obj.TON_TOI_THIEU) + '</td>' +
                            ' <td>' + obj.NHOM_SAN_PHAM.TEN_NHOM_SAN_PHAM + '</td>' +

                            ' <td class ="hidden">' + obj.NHA_SAN_XUAT + '</td>' +
                            ' <td class ="hidden">' + obj.XUAT_XU + '</td>' +
                            ' <td class ="hidden">' + obj.MAU_SAC + '</td>' +
                            ' <td class ="hidden">' + obj.CO_HAN_SU_DUNG + '</td>' +
                            ' <td class ="hidden">' + obj.TON_TOI_DA + '</td>' +
                            ' <td class ="hidden">' + obj.DAI + '</td>' +
                            ' <td class ="hidden">' + obj.RONG + '</td>' +
                            ' <td class ="hidden">' + obj.DAY + '</td>' +
                            ' <td class ="hidden">' + obj.SERIAL + '</td>' +
                            ' <td class ="hidden">' + obj.HINH + '</td>' +
                            ' <td class ="hidden"> ' + obj.NGUOI_SUA + '</td>' +
                            ' <td class ="hidden">' + obj.LAN_SUA_CUOI + '</td>' +
                            ' <td class ="hidden">' + obj.NHOM_SAN_PHAM.MA_NHOM_SAN_PHAM + '</td>' +
                            ' <td class ="hidden">' + obj.MO_TA + '</td>' +
                            ' </tr>');
                        });

                    },
                    error: function (data) {
                        console.log(data.d);
                    }

                });
            }

            onload = function () {
                BlockUI();
                var tables = document.getElementById("table_san_pham");
                TimSanPham('', tables.rows.length - 1);
                TimNhomSanPham('', 0);
            }

            function ThemMoiSanPham() {
                if (!Kiemtrahople()) {
                    return false;
                }
                BlockUIPopover();
                var SANPHAM = {};
                SANPHAM.MA_SAN_PHAM = $('#txt_ma_sp').val();
                SANPHAM.MA_NHOM_SAN_PHAM = $('#cbo_nhom_sp').val();
                SANPHAM.TEN_SAN_PHAM = $('#txt_ten_sp').val();
                SANPHAM.GIA_BAN = $('#txt_gia_ban').val().toString().replace(/,/g, '');
                SANPHAM.DON_VI_TINH = $('#txt_dvtinh').val();
                SANPHAM.GIAM_GIA = $('#txt_giam_gia').val().toString().replace(/,/g, '');
                SANPHAM.MO_TA = $('#txt_mo_ta').val();
                SANPHAM.NHA_SAN_XUAT = $('#txt_nha_sx').val();
                SANPHAM.XUAT_XU = $('#txt_xuat_xu').val();
                SANPHAM.MAU_SAC = $('#txt_mau_sac').val();
                SANPHAM.CO_HAN_SU_DUNG = $('#chk_hsd').prop('checked');
                SANPHAM.TON_TOI_THIEU = $('#txt_ton_toi_thieu').val().toString().replace(/,/g, '');
                SANPHAM.TON_TOI_DA = $('#txt_ton_toi_da').val().toString().replace(/,/g, '');
                SANPHAM.DAI = $('#txt_dai').val();
                SANPHAM.RONG = $('#txt_rong').val();
                SANPHAM.DAY = $('#txt_day').val();
                SANPHAM.HINH = '';
                SANPHAM.SERIAL = $('#txt_serial').val();
                SANPHAM.NGUOI_SUA = '';

                var DTO = {
                    'SANPHAM': SANPHAM
                };
                $.ajax({
                    type: "POST",
                    url: "../BUSINESS/Services.asmx/ThemMoiSanPham",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $(".popover").unblock();
                        var obj = jQuery.parseJSON(data.d);
                        if (obj.SUCCESS == -1) {
                            MakeToast('danger', 'Lỗi', obj.ERROR);
                        }
                        else {
                            MakeToast('success', 'Thành công', obj.ERROR);
                            XoaText();
                            $("#table_san_pham tbody").html('');
                            var tables = document.getElementById("table_san_pham");
                            var search_term = $("#txt_search").val();
                            TimSanPham(search_term, tables.rows.length - 1);
                        }

                    },
                    error: function (data) {
                        $(".popover").unblock();
                    }

                });
            }

            function CapNhatSanPham() {
                if (!Kiemtrahople()) {
                    return false;
                }
                BlockUIPopover();
                var SANPHAM = {};
                SANPHAM.MA_SAN_PHAM = $('#txt_ma_sp').val();
                SANPHAM.MA_NHOM_SAN_PHAM = $('#cbo_nhom_sp').val();
                SANPHAM.TEN_SAN_PHAM = $('#txt_ten_sp').val();
                SANPHAM.GIA_BAN = $('#txt_gia_ban').val().toString().replace(/,/g, '');
                SANPHAM.DON_VI_TINH = $('#txt_dvtinh').val();
                SANPHAM.GIAM_GIA = $('#txt_giam_gia').val().toString().replace(/,/g, '');
                SANPHAM.MO_TA = $('#txt_mo_ta').val();
                SANPHAM.NHA_SAN_XUAT = $('#txt_nha_sx').val();
                SANPHAM.XUAT_XU = $('#txt_xuat_xu').val();
                SANPHAM.MAU_SAC = $('#txt_mau_sac').val();
                SANPHAM.CO_HAN_SU_DUNG = $('#chk_hsd').prop('checked');
                SANPHAM.TON_TOI_THIEU = $('#txt_ton_toi_thieu').val().toString().replace(/,/g, '');
                SANPHAM.TON_TOI_DA = $('#txt_ton_toi_da').val().toString().replace(/,/g, '');
                SANPHAM.DAI = $('#txt_dai').val();
                SANPHAM.RONG = $('#txt_rong').val();
                SANPHAM.DAY = $('#txt_day').val();
                SANPHAM.HINH = '';
                SANPHAM.SERIAL = $('#txt_serial').val();
                SANPHAM.NGUOI_SUA = '';
                SANPHAM.LAN_SUA_CUOI = $('#lbl_lan_sua_cuoi').html();
                var DTO = {
                    'SANPHAM': SANPHAM
                };
                $.ajax({
                    type: "POST",
                    url: "../BUSINESS/Services.asmx/CapNhatSanPham",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $(".popover").unblock();
                        var obj = jQuery.parseJSON(data.d);
                        if (obj.SUCCESS == -1) {
                            MakeToast('danger', 'Lỗi', obj.ERROR);
                        }
                        else {
                            MakeToast('success', 'Thành công', obj.ERROR);
                            $("#table_san_pham tbody").html('');
                            var tables = document.getElementById("table_san_pham");
                            var search_term = $("#txt_search").val();
                            TimSanPham(search_term, tables.rows.length - 1);
                        }

                    },
                    error: function (data) {
                        $(".popover").unblock();
                    }

                });
            }

            function XoaSanPham() {

                BlockUIPopover();
                var ma_san_pham = [];

                var tables = document.getElementById("table_san_pham");
                var k = -1;
                for (var i = 1; i < tables.rows.length; i++) {
                    var row = tables.rows[i]
                    if (row.className == 'info') {
                        k++;
                        ma_san_pham[k] = row.cells[2].innerHTML;
                    }
                }

                var DTO = {
                    'ma_san_pham': ma_san_pham
                };
                $.ajax({
                    type: "POST",
                    url: "../BUSINESS/Services.asmx/XoaSanPham",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $(".popover").unblock();
                        var obj = jQuery.parseJSON(data.d);
                        if (obj.SUCCESS == -1) {
                            MakeToast('danger', 'Lỗi', obj.ERROR);
                        }
                        else {
                            MakeToast('success', 'Thành công', obj.ERROR);
                            $("#btn_delete").popover('hide');
                            $("#table_san_pham tbody").html('');
                            var tables = document.getElementById("table_san_pham");
                            var search_term = $("#txt_search").val();
                            TimSanPham(search_term, tables.rows.length - 1);
                        }
                    },
                    error: function (data) {
                        $(".popover").unblock();
                    }

                });
            }

            $('body').on('click', '.datepicker', function () {

            });


            $('body').on('click', 'span#btn_ok', function (event) {
                event.preventDefault();
                XoaSanPham();
            });


            $('body').on('click', 'button#btn_save', function (event) {
                event.preventDefault();
                if ($('#txt_ma_sp').is(':disabled')) {
                    CapNhatSanPham();
                }
                else
                    ThemMoiSanPham();
            });


            $("#btn_add").click(function (event) {
                event.preventDefault();

            });

            function CheckTableNguoidung() {
                var tables = document.getElementById("table_san_pham");
                var k = -1;
                for (var i = 0; i < tables.rows.length; i++) {
                    var row = tables.rows[i]
                    if (row.className == 'info') {
                        k = i;
                        break;
                    }
                }
                return k;
            }

            $("#btn_edit").click(function (event) {
                event.preventDefault();
                var k = CheckTableNguoidung();
                if (k != -1) {
                    $(this).popover('show');
                }
            });


            $("#btn_delete").click(function (event) {
                event.preventDefault();
                var tables = document.getElementById("table_san_pham");
                var k = CheckTableNguoidung();
                if (k != -1) {
                    $(this).popover('show');
                }
            });

            $("#btn_refresh").click(function (event) {
                event.preventDefault();
                BlockUI();
                $("#table_san_pham tbody").html('');
                var tables = document.getElementById("table_san_pham");
                var search_term = $("#txt_search").val();
                TimSanPham('', tables.rows.length - 1);
            });


            var table = document.getElementById("table_san_pham");

            $("table").on("click", ":checkbox", function () {
                if ($(this).val() == -1) {
                    if ($(this).is(':checked')) {
                        $("table tr").addClass("info");
                        $("table tr:first").removeClass("info");
                    }
                    else
                        $("table tr").removeClass("info");
                    return;
                }

                if ($(this).is(':checked')) {
                    $(this).parents("tr:first").addClass("info");
                }
                else {
                    $(this).parents("tr:first").removeClass("info");
                }
            });

            $("#chk_check_all").change(function () {

                if (this.checked) {
                    var table = document.getElementById("table_san_pham");
                    $('td input:checkbox', table).prop('checked', this.checked);
                }
                else {
                    var table = document.getElementById("table_san_pham");
                    $('td input:checkbox', table).prop('checked', '');
                }
            });

            $("#txt_search").keyup(function (e) {
                if (e.keyCode == 13) {
                    e.preventDefault();
                    e.stopPropagation();
                    var search_term = $("#txt_search").val();
                    if (search_term != '') {
                        BlockUI();
                        $("#table_san_pham tbody").html('');
                        var tables = document.getElementById("table_san_pham");
                        var search_term = $("#txt_search").val();
                        TimSanPham(search_term, tables.rows.length - 1);
                    }
                }

            });

            $("#btn_add").popover({
                html: true,
                content: function () {
                    return $('#popoverExampleTwoHiddenContent').html();
                },
                title: function () {
                    return $('#popoverExampleTwoHiddenTitle').html();
                },
                placement: 'bottom'

            });

            $("#btn_edit").popover({
                html: true,
                content: function () {
                    return $('#popoverExampleTwoHiddenContent').html();
                },
                title: function () {
                    return $('#popoverExampleTwoHiddenTitle').html();
                },
                placement: 'bottom',
                trigger: 'Click'

            });

            $("#btn_delete").popover({
                html: true,
                content: function () {

                    return $('#popoverConfirm').html();
                },
                title: function () {
                    return '<h4 class="text-center">Xác nhận xóa</h4>';
                },
                placement: 'bottom',
                trigger: 'Click'

            });

            function getFDate(dateObject) {

                var today = new Date(dateObject);
                if (dateObject == '') {
                    today = new Date();
                }
                var dd = today.getDate();
                var mm = today.getMonth() + 1; //January is 0!

                var yyyy = today.getFullYear();
                if (dd < 10) {
                    dd = '0' + dd
                }
                if (mm < 10) {
                    mm = '0' + mm
                }
                var today = dd + '/' + mm + '/' + yyyy;
                return today;
            }

            $('#btn_add').on('shown.bs.popover', function () {

                $('#txt_ngay_sinh').val(getFDate(''));

                $(".popover-content .datepicker").datepicker();

                var h = $(window).height() - 239;
                $(".popover-content").css({
                    'max-height': h
                });
            });

            $('#btn_edit').on('shown.bs.popover', function () {

                $(".popover-content .datepicker").datepicker();

                var tables = document.getElementById("table_san_pham");
                var k = -1;
                for (var i = 0; i < tables.rows.length; i++) {
                    var row = tables.rows[i]
                    if (row.className == 'info') {
                        $('#txt_ma_sp').attr("disabled", "disabled")
                        $('#txt_ma_sp').val(row.cells[2].innerHTML);
                        $('#txt_ten_sp').val(row.cells[3].innerHTML);
                        $('#txt_gia_ban').val(row.cells[4].innerHTML);
                        $('#txt_dvtinh').val(row.cells[5].innerHTML);
                        $('#txt_giam_gia').val(row.cells[6].innerHTML);
                        $('#txt_ton_toi_thieu').val(row.cells[7].innerHTML);
                        $('#txt_nha_sx').val(row.cells[9].innerHTML);
                        $('#txt_xuat_xu').val(row.cells[10].innerHTML);

                        $('#txt_mau_sac').val(row.cells[11].innerHTML);
                        // alert(row.cells[12].innerHTML);
                        if (row.cells[12].innerHTML == 'false') {
                            $('#chk_hsd').prop('checked', '');
                        }
                        else
                            $('#chk_hsd').prop('checked', 'checked');

                        $('#txt_ton_toi_da').val(row.cells[13].innerHTML);
                        $('#txt_dai').val(row.cells[14].innerHTML);
                        $('#txt_rong').val(row.cells[15].innerHTML);
                        $('#txt_day').val(row.cells[16].innerHTML);
                        $('#txt_serial').val(row.cells[17].innerHTML);
                        //$('#hinh').val(row.cells[18].innerHTML);
                        //$('#hinh').val(row.cells[19].innerHTML);
                        $("#lbl_lan_sua_cuoi").html(row.cells[20].innerHTML);
                        $('#cbo_nhom_sp').val(row.cells[21].innerHTML);
                        $('#txt_mo_ta').val(row.cells[22].innerHTML);





                        //' <td class ="hidden">' + obj.TON_TOI_DA + '</td>' +
                        //' <td class ="hidden">' + obj.DAI + '</td>' +
                        //' <td class ="hidden">' + obj.RONG + '</td>' +
                        //' <td class ="hidden">' + obj.DAY + '</td>' +
                        //' <td class ="hidden">' + obj.SERIAL + '</td>' +
                        //' <td class ="hidden">' + obj.HINH + '</td>' +
                        //' <td class ="hidden"> ' + obj.NGUOI_SUA + '</td>' +
                        //' <td class ="hidden">' + obj.LAN_SUA_CUOI + '</td>' +
                        //' <td class ="hidden">' + obj.NHOM_SAN_PHAM.MA_NHOM_SAN_PHAM + '</td>' +
                        //' <td class ="hidden">' + obj.MO_TA + '</td>' +


                        k = i;
                        break;
                    }
                }
                var h = $(window).height() - 239;
                $(".popover-content").css({ 'max-height': h });

            });

            $('#btn_delete').on('shown.bs.popover', function () {
                var tables = document.getElementById("table_san_pham");
                var k = 0;
                for (var i = 0; i < tables.rows.length; i++) {
                    var row = tables.rows[i]
                    if (row.className == 'info') {
                        k++;
                    }
                }
                if (k != 0) {
                    $("#msgcontent").html('Bạn có chắc muốn xóa <strong>' + k + '</strong> sản phẩm ?');
                }
            });

            function TimNhomSanPham(ten_nhom_san_pham, tong_so_dong) {

                var DTO = {
                    'ten_nhom_san_pham': ten_nhom_san_pham,
                    'tong_so_dong': tong_so_dong
                };

                $.ajax({
                    type: "POST",
                    url: "../BUSINESS/Services.asmx/TimNhomSanPhamTheoTen",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $("#cbo_phong_ban").html('');
                        $.each($.parseJSON(data.d), function (idx, obj) {
                            tong_so_dong += 1;
                            $("#cbo_nhom_sp").append(
                                '<option value="' + obj.MA_NHOM_SAN_PHAM + '">' + obj.TEN_NHOM_SAN_PHAM + '</option>');
                        });

                    },
                    error: function (data) {
                        console.log(data.d);
                    }

                });
            }



        });

    </script>
</asp:Content>
